package com.ml.loan.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ml.loan.common.model.PageResult;
import com.ml.loan.common.utils.Convert;
import com.ml.loan.sys.dao.SysFilesMapper;
import com.ml.loan.sys.model.SysFiles;
import com.ml.loan.sys.service.SysFilesService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author milian
 * @since 2022-08-22
 */
@Service
public class SysFilesServiceImpl extends ServiceImpl<SysFilesMapper, SysFiles> implements SysFilesService {

    @Override
    public PageResult<SysFiles> list(Integer page, Integer limit, String startDate, String endDate) {
        LambdaQueryWrapper<SysFiles> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(startDate)) {
            wrapper.ge(SysFiles::getCreateTime, startDate + " 00:00:00");
        }
        if (StringUtils.isNotBlank(endDate)) {
            wrapper.le(SysFiles::getCreateTime, endDate + " 23:59:59");
        }
        wrapper.orderByDesc(SysFiles::getCreateTime);
        Page<SysFiles> dictPage = new Page<>(Convert.toInt(page, 1), Convert.toInt(limit, 10));
        IPage<SysFiles> iPage = baseMapper.selectPage(dictPage, wrapper);
        return new PageResult<>(iPage.getRecords(), iPage.getTotal());
    }
}
